﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Helper;
using CoreData;
namespace SchoolManagementSystem.Report._1._HocVien
{
    class HocVienReportData
    {
        public static DataTable LoadStudentByClass(long ClassID)
        {
            DataTable dt = new DataTable();
            var data = RegisterService.RegisterServices.StudentService.GetByClassID(ClassID);
            if (data == null || data.Count <= 0)
            {
                data = new List<Student>();
            }
            else
            {
                data = data.Where(c => c.Active == false).ToList();
            }
            var l = new KList<CoreData.Student>();
            dt = l.ConvertToDataTable(data);
            return dt;
        }

        public static DataTable LoadTempStudentByMultiCondition(string search)
        {
           
            DataTable dt = new DataTable();
            IList<TempStudent> data;
            try
            {
                 data = RegisterService.RegisterServices.TempStudentService.GetList(search) as IList<TempStudent>;
                if (data == null || data.Count <= 0)
                {
                    data = new List<TempStudent>();
                }
            }
            catch
            {
                data = new List<TempStudent>();
            }
            
            var l = new KList<CoreData.Student>();
            dt = l.ConvertToDataTable(data);
            return dt;
        }

        public static DataTable LoadStudentByCourse(long CourseID)
        {
            DataTable dt = new DataTable();
            var data = RegisterService.RegisterServices.StudentService.GetByCourseID(CourseID);
            if (data == null || data.Count <= 0)
            {
                data = new List<Student>();
            }
          
            var l = new KList<CoreData.Student>();
            dt = l.ConvertToDataTable(data);
            return dt;
        }


        public static DataTable LoadStudentByBranch(long BranchID, DateTime datefrom, DateTime dateto)
        {
            DataTable dt = new DataTable();
            var data = RegisterService.RegisterServices.StudentService.GetByBranchID(BranchID, datefrom,dateto);
            if (data == null || data.Count <= 0)
            {
                data = new List<Student>();
            }
            else
            {
                data = data.OrderByDescending(c => c.DateOfAdmission).ToList();
            }
            var l = new KList<CoreData.Student>();
            dt = l.ConvertToDataTable(data);
            return dt;
        }

        public static DataTable LoadStudentByAllCondition(long BranchID, long CourseID, long ClassID, long StatusID,
           long ChannelID, DateTime datefrom, DateTime dateto, int birthfrom, int birthto)
        {
            DataTable dt = new DataTable();
            var data = RegisterService.RegisterServices.StudentService.GetByMultiCondition(BranchID,CourseID,ClassID,StatusID,ChannelID, datefrom, dateto, birthfrom, birthto);
            if (data == null || data.Count <= 0)
            {
                data = new List<Student>();
            }
            else
            {
                data = data.OrderByDescending(c => c.DateOfAdmission).ToList();
            }
            var l = new KList<CoreData.Student>();
            dt = l.ConvertToDataTable(data);
            return dt;
        }

        public static DataTable LoadTongKetSoLNhapHocVaRaTruongNganHan(int Year)
        {
            DataTable dt = new DataTable();
            var data = (List<Class>)RegisterService.RegisterServices.ClassService.GetList(" Class.Type = 0 and Year(Course.StartDate) =" +Year);
            if (data == null || data.Count <= 0)
            {
                data = new List<Class>();
            }
            else
            {
                data = data.OrderByDescending(c => c.StartDate).ToList();
            }
            var l = new KList<CoreData.Student>();
            dt = l.ConvertToDataTable(data);
            return dt;
        }

        public static DataTable LoadReportClassNotDone(string SearchString)
        {
            return RegisterService.RegisterServices.ClassService.GetReportClassNotDone(SearchString);
        }



    }


}
